# _*_ coding: UTF-8 _*_
# @Time     : 2021/1/22 下午 02:26
# @Author   : Li Jie
# @Site     : http://www.hzdledu.com/
# @File     : index_prac.py
# @Software : PyCharm

# 目录操作
import os
# 绝对路径和相对路径
def foo1():
    print(os.path.abspath(r'file_test.py'))

    path = os.path.join(r'D:\pyworkspace\test\c10', r'file_test.py')
    print(path)

#判断路径是否存在
def foo2():
    path1 = r'd:\pyworkspace'
    path2 = r'D:\pyworkspace\test\c10\file_test.py'
    print(os.path.exists(path1))
    print(os.path.exists(path2))


def foo3():
    """
    创建一级目录
    :return:
    """
    path = r'D:\pyworkspace\test\c10\test'
    os.mkdir(path,mode=0o777)

def foo4():
    """
    创建多级目录
    :return:
    """
    path = r'D:\pyworkspace\test\c10\test1\test2'
    os.makedirs(path,mode=0o777)

def foo5():
    """
    删除目录
    :return:
    """
    path = r'D:\pyworkspace\test\c10\test'
    os.rmdir(path)

def foo6():
    """
    遍历目录
    :return:
    """
    path = r'D:\pyworkspace\test\c10'
    tuple1 = os.walk(path)
    for i in tuple1:
        print(i)

def foo7():
    """
    删除文件
    :return:
    """
    os.remove('test.txt')

def foo8():
    """
    重命名文件或目录
    :return:
    """
    os.rename('test.txt','test10.txt')

def foo9():
    """
    获取文件信息
    :return:
    """
    fileinfo = os.stat('test1.txt')
    print(f'文件大小：{fileinfo.st_size}bytes')
    print(f'文件创建时间：{fileinfo.st_ctime}')


if __name__ == '__main__':
    # foo1()
    # foo2()
    # foo3()
    # foo4()
    # foo5()
    # foo6()
    # foo7()
    # foo8()
    foo9()